#include "BattleLineApplication.h"
#include "../BoardGameBase/BaseApplication.h"
#include "BattleLineFrameListener.h"

CBattleLineApplication::CBattleLineApplication(void)
{
}

CBattleLineApplication::~CBattleLineApplication(void)
{
}

void CBattleLineApplication::createScene(void)
{
//set light
	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
	mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
	
	Light* light = mSceneMgr->createLight("Light1");
	light->setType(Light::LT_POINT);
	light->setPosition(Vector3(0, 150, 250));
	light->setDiffuseColour(1.0, 0.0, 0.0);
	light->setSpecularColour(1.0, 0.0, 0.0);

//set mesh
	Plane plane(Vector3::UNIT_Y, 0);
	MeshManager::getSingleton().createPlane("ground",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
		1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
	Entity *ent = mSceneMgr->createEntity("GroundEntity", "ground");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
	ent->setMaterialName("Examples/Rockwall");
	ent->setCastShadows(false);

	Entity *ent1 = mSceneMgr->createEntity("Ninja1", "ninja.mesh");
	SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode" );
	node1->attachObject( ent1 );

	Entity *ent2 = mSceneMgr->createEntity("Ninja2", "ninja.mesh");
	SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode2", Vector3( 50, 0, 0 ) );
	node2->attachObject( ent2 );

}

void CBattleLineApplication::destroyScene()
{

}

void CBattleLineApplication::createCamera()
{
	mCamera = mSceneMgr->createCamera("PlayerCam");

	// set its position, direction  
	mCamera->setPosition(Vector3(0,10,500));
	mCamera->lookAt(Vector3(0,0,0));
	mCamera->setNearClipDistance(5);

	// Create the scene node
	SceneNode * node;
	
	node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Vector3(-400, 200, 400));
	node->yaw(Degree(-45));
	node->attachObject(mCamera);

	// create the second camera node
	node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode2", Vector3(0, 200, 400));
}

void CBattleLineApplication::createFrameListener(void)
{
	mFrameListener= new CBattleLineFrameListener(mWindow, mCamera,mSceneMgr);
	mFrameListener->showDebugOverlay(true);
	mRoot->addFrameListener(mFrameListener);
}